﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Extension
{
    public static class Extensions
    {
        public static StringBuilder Substring(this StringBuilder sb, int start, int length)
        {

            string ss = sb.ToString();
            ss = ss.Substring(start, length);

            StringBuilder builded = new StringBuilder(ss);

            return builded;
        }

        public  static  decimal  SumElements<T>(this IEnumerable<T> list)  
        {
            decimal sum = 0;
            foreach (var item in list)
            {
                sum += Convert.ToDecimal(item);
            }
            return sum;
        }

        public static decimal ProductOfElements<T>(this IEnumerable<T> list)
        {
            decimal product = 1;

            foreach (var item in list)
            {
                product *= Convert.ToDecimal(item);
            }
            return product;
        }
    } 

    class ExtensionExercise
    {
        static void Main(string[] args)
        {
            SortedSet<int> ss = new SortedSet<int>();
            ss.Add(8);
            ss.Add(3);
            ss.Add(5);

            Console.WriteLine(ss.SumElements<int>());
            Console.WriteLine(ss.ProductOfElements<int>());

        }
    }
}
